package demo1;

/**
 * @Author 12629
 * @Description：
 */
class Animal {
    public String name;
    public int age;

    public Animal(String name,int age) {
        this.name = name;
        this.age = age;
    }

    public  void eat() {
        System.out.println(this.name +" 正在吃饭...");
    }
}
// is a
class Dog extends Animal {
    //public String name;
    public Dog(String name,int age) {
        super(name,age);
    }
    public void bark() {
        System.out.println(name + "正在汪汪汪....");
    }

    @Override
    public void eat() {
        System.out.println(this.name+" 正在吃狗粮...");
    }
}
//  子类/派生类     父类/基类/超类
class Bird extends Animal {
    public Bird(String name,int age) {
        super(name,age);
    }
    public void fly() {
        System.out.println(this.name +" 正在飞....");
    }

    @Override
    public void eat() {
        System.out.println(this.name+" 正在吃鸟粮...");
    }
}

public class Test {

    public static void main(String[] args) {
        Animal animal1 = new Dog("旺财",10);
        if(animal1 instanceof Dog) {
            Dog dog = (Dog)animal1;
            dog.bark();
        }else {
            System.out.println("animal1没有引用Dog实例");
        }
        System.out.println("===========");
        if(animal1 instanceof Bird) {
            Bird bird = (Bird) animal1;
            bird.fly();
        }else {
            System.out.println("animal1没有引用Bird实例");
        }
    }

    public static Animal test2() {
        return new Dog("旺财",10);
    }

    public static void test1(Animal animal) {
        animal.eat();
    }

    public static void main2(String[] args) {
        Animal animal1 = new Dog("旺财",10);
        test1(animal1);

        Animal animal2 = new Bird("小鸟",1);
        test1(animal2);

        //animal.eat();
        //animal.bark();
    }

    public static void main1(String[] args) {
        Animal animal = new Dog("旺财",10);
        test1(animal);

        Dog dog = new Dog("旺财",10);
        dog.bark();
        dog.bark();

        new Dog("旺财2",10).bark();
        new Dog("旺财2",10).bark();

    }
}
